<template>
  <a-modal
    :visible="visible"
    :afterClose="hanldeAfterClose"
    @cancel="close"
    @ok="handleSubmit"
    :confirmLoading="isSubmiting"
    title="换房审核"
  >
    <a-form :form="form">
      <a-form-item label="审核结果">
        <a-radio-group v-decorator="['HF_SHZT', { rules: [{ required: true, message: '请选择审核结果' }] }]">
          <a-radio value="符合"> 符合 </a-radio>
          <a-radio value="不符合"> 不符合 </a-radio>
        </a-radio-group>
      </a-form-item>
      <a-form-item label="不符合原因" v-show="form.getFieldValue('HF_SHZT') === '不符合'">
        <a-textarea
          v-decorator="[
            'HF_SHMS',
            {
              initialValue: '',
              rules: [{ required: form.getFieldValue('HF_SHZT') === '不符合', message: '请输入不符合原因' }],
            },
          ]"
        />
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
import { postChangeHouseAudit } from '@/api/cityReviewAndManage'
import moment from 'moment'
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    data: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      form: this.$form.createForm(this, { name: 'changeHouseAudit' }),
      isSubmiting: false
    }
  },
  methods: {
    handleSubmit () {
      this.form.validateFields((err, values) => {
        if (!err) {
          this.isSubmiting = true
          const { HF_SHZT, HF_SHMS } = values
          postChangeHouseAudit({
            State: 'SH',
            ZC_HTXX: {
              ID: this.data.ID,
              HF_SHSJ: moment().format('YYYY-MM-DD HH:mm:ss'),
              HF_SHZT,
              HF_SHMS,
              HF_SHUserID: this.$store.getters.userid
            }
          }).then((res) => {
            this.$message.success(`换房审核成功`)
            this.$emit('success')
            this.close()
          }).finally(() => {
            this.isSubmiting = false
          })
        }
      })
    },
    close () {
      this.$emit('update:visible', false)
      this.$emit('update:data', {})
      this.isSubmiting = false
    },
    hanldeAfterClose () {
      this.form.resetFields()
    }
  }
}
</script>
<style lang="less" scoped>
</style>
